﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// WMS把库存物料的转储（从SAP的一个库存地点到另一个库存地点，或报废出库，委外发运、零星出入库）执行结果传到SAP
    /// </summary>
    public class WMSInventoryDumpResultJob : IJobService
    {
        private readonly IWMSInterfaceMasterRepository repository;


        public WMSInventoryDumpResultJob(IWMSInterfaceMasterRepository _repository)
        {
            this.repository = _repository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<WmsMovrInterface> wmsMovrs = repository.GetInventoryDumpResultInfo();
                if (wmsMovrs.Count <= 0)
                {
                    return "没有待处理的库存转储结果信息！";
                }

                SapInterfaceResult result = repository.InsertInventoryDumpResultInfo(wmsMovrs);
                return result.message;
            }
            catch (Exception ex)
            {
                LogHelper.Error("库存转储结果接口错误！" + ex);
                return "库存转储结果接口错误！" + ex.Message;
            }
        }
    }
}
